(function (angular) {

    angular
        .module('movie.directives.auto_active', [])
        .directive('autoActive', ['$location', function ($location) {
            return {
                //当这个指定作用域某个元素后触发一次
                link: function (scope, element, attributes) {
                    let url = $location.url();
                    scope.$location = $location;
                    scope.$watch('$location.url()', function (now, old) {
                        let aLink = element.children().attr('href').substr(1);
                        if (now.startsWith(aLink)) {
                            element.parent().children().removeClass(attributes.autoActive);
                            //给当前元素加上active样式
                            element.addClass(attributes.autoActive);
                        }
                    });

                }
            }
        }])
})(angular);
